/*
*Copyright (c) Nikhil Jain.
*Project ICARUS, communications and 
*artificial intelligence.
*/



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package javadrone.server;

//~--- non-JDK imports --------------------------------------------------------

import javadrone.Drone;
import javadrone.State;

import javadrone.command.Command;
import javadrone.command.CommandQueue;
import javadrone.command.RealTimeCommand;

//~--- JDK imports ------------------------------------------------------------

import java.awt.image.BufferedImage;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author Nikzzay
 */
public class DroneImpl extends UnicastRemoteObject implements Drone, GenericDrone {
    private CommandQueue cQueue;
    private String       description;
    private StateImpl    state;

    public DroneImpl(CommandQueue cQueue, String description) throws RemoteException {
        this.state       = new StateImpl(this);
        this.cQueue      = cQueue;
        this.description = description;
    }

    public void setState(StateImpl state) {
        this.state = state;
    }

    @Override
    public State getState() throws RemoteException {
        return state;
    }

    public StateImpl getCompleteState() {
        return state;
    }

    @Override
    public Command takeCommand() throws InterruptedException, RemoteException {
        return cQueue.take();
    }

    @Override
    public void putCommand(Command c) {

        // System.out.println("Put command :"+c+" Command in queue: "+cQueue.size());
        cQueue.put(c);
    }

    @Override
    public void putCommand(RealTimeCommand rtc) {
        System.out.println("Put realtime command :" + rtc + " Command in queue: " + cQueue.size());
        cQueue.put(rtc);
    }

    @Override
    public String getDescription() throws RemoteException {
        return description;
    }

    @Override
    public int commandsInQueue() throws RemoteException {
        return cQueue.size();
    }

    @Override
    public Command pollCommand() throws RemoteException {
        return cQueue.poll();
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
